<template>
	<view class="content">
		<view class="item" v-for="(item,index) in orderList" :key="index">
			<view class="box">
				<view class="namebox mt-16">
					<view class="name">{{item.name}}</view>
					<view class="price">￥ {{item.price}}</view>
				</view>
				<view class="date mt-16">
					<text>{{item.startDate}}</text>
					<text class="mlr">-</text>
					<text>{{item.endDate}}</text>
				</view>
				<view class="info mt-16">
					<text class="mr-30">{{item.color}}</text>
					<text class="mr-30">{{item.oilType}}</text>
					<text class="mr-30">{{item.km}}</text>
					<text class="mr-30">{{item.license}}</text>
					<text>{{item.age}}</text>
				</view>
				<view class="button">
					<view class="btn" @click="chooseOrder">抢单</view>
				</view>
			</view>
		</view>
		<uni-popup ref="orderOpinion" type="center">
			<view class="order-body">
				<view class="d-flex space-between" style="margin-bottom: 70rpx;">
					<view></view>
					<text class="opinion">抢单意向</text>
					<img @click="closePopUp" class="close-img" :src="closImg" alt="">
				</view>
				<view class="item-body" v-for="(item,index) in myCarList" :key="index">
					<checkbox @click="itemClick(index)" :checked="item.check" />
					<view class="item-right">
						<view class="right-carType">{{item.carType}}</view>
						<view class="item-info">
							<view>ID：{{item.id}}</view>
							<view>车牌：{{item.license}}</view>
							<view>状态：{{item.state}}</view>
						</view>
					</view>
				</view>
				<view class="btn-box">
					<view class="grabOrder-btn" @click="confirmGrab">
						<view>确认抢单</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import icons from '../../../common/icons.js'
	import request from '../../../requst.js'
	export default {
		components: {
			uniPopup
		},
		data() {
			return {
				closImg: icons.icons.close,
				orderList: [{
						name: "法拉利 458",
						startDate: "2020/08/02",
						endDate: "2020/08/02",
						color: '红色',
						oilType: "98号油",
						km: "15.3",
						license: "粤B",
						age: "2",
						price: "1500"
					},
					{
						name: "法拉利 458",
						startDate: "2020/08/02",
						endDate: "2020/08/02",
						color: '红色',
						oilType: "98号油",
						km: "15.3",
						license: "粤B",
						age: "2",
						price: "1500"
					},
					{
						name: "法拉利 458",
						startDate: "2020/08/02",
						endDate: "2020/08/02",
						color: '红色',
						oilType: "98号油",
						km: "15.3",
						license: "粤B",
						age: "2",
						price: "1500"
					},
				],
				myCarList: [{
						check: false,
						carType: "法拉利 488",
						id: "0001",
						license: "粤B 888888",
						state: '可用'
					},
					{
						check: false,
						carType: "法拉利 488",
						id: "0002",
						license: "粤B 888888",
						state: '可用'
					}
				],

			}
		},
		onLoad(){
			this.getGrabOrder();
		},
		methods: {
			chooseOrder() {
				this.$refs.orderOpinion.open();
			},
			closePopUp() {
				this.$refs.orderOpinion.close();
			},
			confirmGrab() {
				var checkList = [];
				for (var i = 0; i < this.myCarList.length; i++) {
					checkList.push(this.myCarList[i].check);
				}
				if (checkList.indexOf(true) == -1) {
					uni.showToast({
						title: "请先选择意向车辆",
						icon: 'none',
					})
				} else {
					uni.showToast({
						title: '抢单成功，请在我的订单-供车订单查看',
						icon: 'none',
						success: () => {
							this.$refs.orderOpinion.close();
						}
					})

				}
			},
			itemClick(index) {
				this.myCarList[index].check = !this.myCarList[index].check;
			},
			getGrabOrder() {
				request({
					url: 'qijian/personalCentre/availableCar',
					success: res => {
						console.log(res);
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #EFEFF4;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>

<style scoped>
	.btn-box {
		border-top: 1px solid #D6D6D6;
		padding: 60rpx 0 20rpx 0;
		/* margin-top: 20rpx; */
	}

	.grabOrder-btn {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 80vw;
		height: 88rpx;
		background: #000000;
		border-radius: 6px;
		font-size: 36rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #B6914E;

	}

	.item-info {
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		width: 68vw;
	}

	.right-carType {
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}

	.item-right {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		align-items: flex-start;
		width: 68vw;
	}

	.item-body {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-top: 1px solid #D6D6D6;
		/* border-bottom: 1px solid #D6D6D6; */
		padding: 20rpx 0;
	}

	.d-flex {
		display: flex !important;
	}

	.space-between {
		justify-content: space-between !important;
	}

	.close-img {
		width: 28rpx;
		height: 28rpx;
	}

	.opinion {
		font-size: 36rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
	}

	.order-body {
		width: 80vw;
		min-height: 34.85vh;
		background-color: #FFFFFF;
		box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.5);
		padding: 40rpx;
		border-radius: 12px;
		margin-bottom: 20vh;
	}

	.btn {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 60px;
		height: 28px;
		border-radius: 6px;
		border: 1px solid #B6914E;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #B6914E;
	}

	.button {
		display: flex;
		justify-content: flex-end;
		padding: 20rpx 0;
		border-top: 1px solid #F4F4F4;
	}

	.info {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		margin-bottom: 15rpx;

	}

	.mlr {
		margin: 0 6rpx;
	}

	.date {
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #292929;
	}

	.namebox {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.name {
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #292929;
	}

	.box {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		width: 90vw;
	}

	.mr-12 {
		margin-right: 12rpx;
	}

	.mr-30 {
		margin-right: 50rpx;
	}

	.mt-16 {
		margin-top: 16rpx;
	}

	.m-0 {
		margin: 0;
	}

	.price {
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #B6914E;
	}

	.item {
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #FFFFFF;
		margin-top: 16rpx;
		padding: 10rpx 0 0 0;

	}

	.content {
		display: flex;
		flex: 1;
		flex-direction: column;
		width: 100vw;
	}
</style>
